{template header}
<style type="text/css">
    .popup {
        background-color: whitesmoke;
        display: none;
        padding: 10px;
        border: 2px solid #ddd;
        position: fixed;
        top: 50%;
        left: 50%;
        width:250px;
        height:250px;
        z-index: 99999;
    }
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <span>上传安装包</span>
</h4>
<form class="form-horizontal" method="post" action="?c=admin&a=uploadAppPackage" enctype="multipart/form-data" id="form1">
    <div class="control-group search-group" style="margin:0;">
        <label class="control-label" >版本号：</label>
        <div class="controls">
           <input type="text" value="" name="versionCode" />
        </div>
    </div>
    <div class="control-group search-group" style="margin:0;">
        <div class="controls">
            <input type="file" name="apkFile" />
            <input class="btn" type="button" id="btn" value="提交" />
        </div>
    </div>
</form>
<div class="bs-docs-example table-align pt-15" style="clear:both;">
    <table class="table table-striped table-align">
        <thead>
        <tr>
            <th>上传时间</th>
            <th>版本名</th>
            <th>版本号</th>
            <th>安装包名</th>
            <th>文件md5值</th>
            <th>下载地址</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        {if count($info)>0}
        <tbody>
        {loop $info $k $v}
            <tr>
                <td>{eval echo date("Y-m-d H:i:s",$v['create_time'])}</td>
                <td>{$v['version_name']}</td>
                <td>{$v['version_num']}</td>
                <td>{$v['name']}</td>
                <td>{$v['file_hash']}</td>
                <td>{$v['file_url']}</td>
                <td>
                    {if $v['status'] == 1}
                     更新中
                    {else}
                      更新
                    {/if}
                </td>
                <td>
                    <a class="btn btn-primary" href="?c=admin&a=setAppPackage&id={$v['id']}">设置</a>&nbsp;&nbsp;
                    {if $v['status'] == 0}
                        <button class="btn btn-primary" id="add_{$v['id']}" ids="{$v['id']}">更新</button>&nbsp;&nbsp;
                    {/if}
                    {if $v['status'] == 1}
                    <button class="btn btn-primary" id="save_{$v['id']}" ids="{$v['id']}">更新中</button>&nbsp;&nbsp;
                    {/if}
                </td>
                <td>
                    <div class="bg" id="bg_{$v['id']}"></div>
                    <div class="popup" id="popup_{$v['id']}">
                        <textarea style="width:235px;height: 200px" id="reason_{$v['id']}"></textarea>
                        <div style="text-align: center">
                            <button class="btn btn-primary" onclick="handle({$v['id']})">确定</button>&nbsp;&nbsp;
                            <button class="btn btn-primary" onclick="$('.popup').hide();$('.bg').hide()">取消</button>
                        </div>
                    </div>
                </td>
            </tr>

        {/loop}
        <div id="res"></div>
        </tbody>
        {/if}
    </table>

</div>
<div class="pagination">
    <ul>
        {$pageStr}
    </ul>
</div>
{template footer}
<div class="bg" id="bgx"></div>
<div id="loading" style="position: absolute; z-index: 1003;background-color:white; display: none;" >
    <img src="{eval echo common::realUrl('images/icon/ios.gif')}" />
</div>


<script type="text/javascript">
    $('#btn').click(function(){
       var version = $("input[name='versionCode']").val();
        if (!version) {
            alert('版本号必填');return false;
        }
        $("#bgx").show();
        $('#form1').submit();
        $("#loading").fadeIn(300);
        letDivCenter('#loading');
    })

    $("button[id^='add_']").on('click',function(){
        if (!confirm('确定更新？')) {
          return false;
        }
        var ids = $(this).attr('ids');
        $.ajax({
            type:'POST',
            url:'?c=admin&a=ajaxsetPackageStatus',
            data:{apkId:ids,status:1},
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.reload();
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })

    $("button[id^='save_']").on('click',function(){
        if (!confirm('确定取消更新?')) {
            return false;
        }
        var ids = $(this).attr('ids');
        $.ajax({
            type:'POST',
            url:'?c=admin&a=ajaxsetPackageStatus',
            data:{apkId:ids,status:0},
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.reload();
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })

    function letDivCenter(divName){
        var divObj = $(divName);
        var wWidth = $(document.body).width(),wHeight = $(window).height();
        var divWidth = divObj.width(),divHeight = divObj.height();
        divObj.css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop(),'display':'block'});
        $(window).bind('scroll resize',function(){
            $(divName).css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop()});
        });
    }

</script>
